#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include <functional>
using namespace std;
int largestArea(vector<string>& grid) {
	int dx[4] = { 0,0,1,-1 }, dy[4] = {1,-1,0,0};
	int m = grid.size(), n = grid[0].size();
	vector<vector<bool>> visited(m, vector<bool>(n, false));
	int ret = INT_MIN;
	auto bfs = [&](int i, int j,char c,int k)
	{
		queue<pair<int, int>> q;
		q.push({ i, j });
		int path = 1;
		while (!q.empty())
		{
			auto [x1, y1] = q.front();
			q.pop();
			visited[x1][y1] = true;
			for (int k = 0; k < 4; k++)
			{
				int x2 = x1 + dx[k], y2 = y1 + dy[k];
				if (x2 >= 0 && x2 < m && y2 >= 0 && y2 < n
					&& visited[x2][y2]==false && grid[x2][y2]==c)
				{
					visited[x2][y2] = true;
					q.push({ x2,y2 });
					path++;
				}
			}
		}
		if (k == 1)
			ret = max(ret, path);
	};
	for (int i = 0; i < m; i++)
	{
		for (int j = 0; j < n; j++)
		{
			if ((i == 0 || i == m - 1 || j == 0 || j == n - 1) && visited[i][j] == false 
				&& grid[i][j]!='0')
			{
				bfs(i, j, grid[i][j], 0);
			}
			else if (grid[i][j] == '0')
			{
				for (int k = 0; k < 4; k++)
				{
					int x = i + dx[k], y = j + dy[k];
					if (x >= 0 && x < m && y >= 0 && y < n
						&& visited[x][y] == false && grid[x][y] != '0')
					{
						bfs(x, y, grid[x][y], 0);
					}
				}
			}
		}
	}
	for (int i = 0; i < m; i++)
	{
		for (int j = 0; j < n; j++)
		{
			if (visited[i][j] == false && grid[i][j] != '0')
			{
				bfs(i, j, grid[i][j], 0);
			}
			
		}
	}
	return ret;
}
int islandPerimeter(vector<vector<int>>& grid) {
	int m = grid.size();
	if (m == 0)
		return 0;
	int n = grid[0].size();
	int ret = 0;
	for (int i = 0; i < m; i++)
	{
		for (int j = 0; j < n; j++)
		{
			if (grid[i][j] == 1)
			{
				ret += 4;
				if (j + 1 < n && grid[i][j + 1] == 1)
					ret -= 2;
				if (i+1<m&&grid[i + 1][j] == 1)
					ret -= 2;
			}
		}
	}
	return ret;
}
int main()
{
	int n, k;
	std::cin >> n >> k;
	std::vector<int> ans;
	std::function<void(int,int)> cal = [&](int x, int sum) -> void {
		if (x >= n) {
			ans.push_back(sum);
			return;
		}
		for (int i = 0; i < k; i++) {
			cal(x + 1, sum * 10 + i);
		}
	};
	cal(0, 0);
	for (int i = 0; i < ans.size(); i++)std::cout << ans[i] << " \n"[i == ans.size() - 1];
	return 0;
}